package Leetcode_Second_Brush;

public class Solution318 {
    public int maxProduct(String[] words) {
        int[] word2int = new int[words.length];

        for (int i = 0; i < words.length; i++) {
            int temp = 0;
            for (int j = 0; j < words[i].length(); j++)
                temp |= 1 << (words[i].charAt(j) - 'a');
            word2int[i] = temp;
        }

        int result = 0;
        for (int i = 0; i < words.length; i++)
            for (int j = i + 1; j < words.length; j++) {
                if ((word2int[i] & word2int[j]) == 0)
                    result = Math.max(result, words[i].length() * words[j].length());
            }

        return result;
    }
}
